package thread.ch02;

import java.io.IOException;
import java.math.BigInteger;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;

import thread.annotation.ThreadSafe;

/**
 * StatelessFactorizer是无状态的：它不包含域也没有引用其他类的域。一次特定计算的瞬时状态，会唯一地存在本地变量中，
 * 这些本地变量存储在线程的栈中
 * ，只要执行的线程才能访问。一个访问StatelessFactorizer的线程，不会影响访问同一个Servlet的其他线程的计算结果
 * ：因为两个线程不共享状态，它们如同在访问不同的实例
 * 
 * @author Administrator
 * 
 */
@ThreadSafe
public class StatelessFactorizer extends HttpServlet {

	@Override
	public void service(ServletRequest request, ServletResponse response)
			throws ServletException, IOException {
		BigInteger i = extractFromRequest(request);
		BigInteger[] factors = factor(i);
		encodeIntoResponse(response, factors);
	}

	private void encodeIntoResponse(ServletResponse response,
			BigInteger[] factors) {
		// TODO Auto-generated method stub

	}

	private BigInteger[] factor(BigInteger i) {
		// TODO Auto-generated method stub
		return null;
	}

	private BigInteger extractFromRequest(ServletRequest request) {
		// TODO Auto-generated method stub
		return null;
	}

}
